import java.util.Stack;

class MinStack {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MinStack() {
        stack1=new Stack<>();
        stack2=new Stack<>();
    }
    
    public void push(int val) {
        stack1.push(val);
        if(stack2.empty()){
            stack2.push(val);
        }else{
            Integer peekVal=stack2.peek();
            if(val<=peekVal){
                stack2.push(val);
            }
        }
    }
    
    public void pop() {
        if(stack1.empty()){
            return;
        }
        int popVal=stack1.peek();
        stack1.pop();
        if(popVal== stack2.peek()){
            stack2.pop();
        }
    }
    
    public int top() {
        if(stack1.empty()){
            return -1;
        }
        return stack1.peek();
    }
    
    public int getMin() {
        if(stack1.empty()){
            return -1;
        }
        return stack2.peek();
    }
}